/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googlecharttest;

import GoogleChartFactory.ChartTypes;
import GoogleChartFactory.GoogleChartFactory;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 *
 * @author Admin
 */
public class GoogleChartTest extends Application {
    
    @FXML private ImageView imageView;
    @FXML private AnchorPane rootPane;
    @FXML private Label urlLabel;
    
    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainScene.fxml"));
        fxmlLoader.setController(this);
        
        fxmlLoader.load();

        stage.setScene(new Scene(rootPane));
        stage.show();
        
        urlLabel.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                try {
                    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
                    //java.net.URI uri = new java.net.URI(URLEncoder.encode(urlLabel.getText(),"UTF-8") );
                    java.net.URI uri = new java.net.URI(urlLabel.getText().replace("|", "%7C" ));
                    desktop.browse( uri );
                } catch (IOException ex) {
                    Logger.getLogger(GoogleChartTest.class.getName()).log(Level.SEVERE, null, ex);
                } catch (URISyntaxException ex) {
                    Logger.getLogger(GoogleChartTest.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
        urlLabel.setOnMouseEntered(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                urlLabel.setTextFill(Color.BLUE);
                rootPane.setCursor(Cursor.HAND);
            }
        });
        
        urlLabel.setOnMouseExited(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                urlLabel.setTextFill(Color.BLACK);
                rootPane.setCursor(Cursor.DEFAULT);
            }
        });
        
        String result = "";
        
        /*
        Map<String, Number> values = new HashMap<>();
        values.put("Data1", 5);
        values.put("Data2", 10);
        values.put("Data3", 20);
        values.put("Data4", 30);
        values.put("Data5", 35);
        Integer height = 500;
        Integer width = 500;
        ChartTypes.PieCharts type = ChartTypes.PieCharts.standart3D;
        result = GoogleChartFactory.createPieChart(values, height, width, type);
        */
        
        
        Map<String, List<Number>> values = new HashMap<>();
        List<Number> data1 = new ArrayList<>();
        List<Number> data2 = new ArrayList<>();
        data1.add(1);
        data1.add(2);
        data1.add(3);
        data1.add(4);
        data1.add(5);
        
        data2.add(5);
        data2.add(4);
        data2.add(3);
        data2.add(2);
        data2.add(1);
        
        values.put("Data1", data1);
        values.put("Data2", data2);
        
        Integer height = 500;
        Integer width = 500;
        ChartTypes.BarCharts type = ChartTypes.BarCharts.VerticalOverlaped;
        result = GoogleChartFactory.createBarChart(values, height, width, type);
        //result = GoogleChartFactory.createLineChart(values, height, width, ChartTypes.SimpleLineCharts.Standart);
        
        
        /*
        Map<String, Map<Number, Number>> values = new HashMap<>();
        Map<Number,Number> line1 = new HashMap<>();
        Map<Number,Number> line2 = new HashMap<>();
        
        line1.put(1, 1);
        line1.put(2, 1.5);
        line1.put(3, 2);
        line1.put(5, 1);
        
        
        line2.put(0, 0);
        line2.put(1, 1);
        line2.put(2, 0);
        line2.put(3, 2);
        line2.put(4, 0);
        line2.put(5, 1);
        line2.put(6, 0);
        
        values.put("Line 1", line1);
        values.put("Line 2", line2);
        
        Integer height = 500;
        Integer width = 500;
        ChartTypes.LineCharts type = ChartTypes.LineCharts.NoAxis;
        result = GoogleChartFactory.createXYLineChart(values, height, width, type);
        */
        
        
        urlLabel.setText(result);
        Image image = new Image(result);
        imageView.setImage(image);
        
        
    }

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}
